package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class LoginDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入用户名");
        String username = sc.nextLine();
        System.out.println("输入密码");
        String password = sc.nextLine();

        try(Connection connection = DBUti1.getconnection();) {
            Statement statement = connection.createStatement();
            String sql = "select id,username,password,nickname,age " +
                        "from user " +
                        "where username='"+username+"'and password='"+password+"'";
            ResultSet r = statement.executeQuery(sql);
            if (r.next()){
                System.out.println("成功");
            }else {
                System.out.println("失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
